using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Network;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class CommonSettingView : BasePage
	{
		private SysSettings mSysSettings;
		private bool mFlagSettingsChanged;
		private bool mFlagAccountStatusChanged;
		private bool initState;
		internal Grid LayoutRoot;
		internal ScrollViewer scrollViewer;
		internal Grid ContentPanel;
		internal MMToggleSwitch toggleNewMsgNotify;
		internal MMToggleSwitch toggleNotifyWithDetail;
		internal MMToggleSwitch toggleSound;
		internal MMToggleSwitch toggleVibrate;
		internal MMToggleSwitch togglePlayBySpeakPhone;
		internal MMToggleSwitch toggleAutoAddFriend;
		internal MMToggleSwitch toggleAutoSavePhotos;
		internal MMToggleSwitch toggleBackground;
		internal MMToggleSwitch toggleExitComfirm;
		internal ListPicker listPickerLanguage;
		internal ListPicker listPickerSkin;
		private bool _contentLoaded;
		public CommonSettingView()
		{
			this.InitializeComponent();
			base.add_Unloaded(new RoutedEventHandler(this.DoFinish));
			base.add_Loaded(new RoutedEventHandler(this.onPageLoaded));
		}
		private void onPageLoaded(object sender, RoutedEventArgs e)
		{
			this.listPickerSkin.SelectionChanged += new SelectionChangedEventHandler(this.skinSelectionChanged);
			this.listPickerLanguage.SelectionChanged += new SelectionChangedEventHandler(this.languageSelectionChanged);
		}
		private void initSelector()
		{
			if (MMTheme.getThemeType() == MMThemeTypes.COOL_BLACK_THEME)
			{
				this.listPickerSkin.SelectedIndex = 0;
			}
			else
			{
				this.listPickerSkin.SelectedIndex = 1;
			}
			if (this.mSysSettings != null)
			{
				string strUserSetLanguage = this.mSysSettings.strUserSetLanguage;
				if ("zh-CN" == strUserSetLanguage)
				{
					this.listPickerLanguage.SelectedIndex = 0;
				}
				else
				{
					if ("zh-TW" == strUserSetLanguage)
					{
						this.listPickerLanguage.SelectedIndex = 1;
					}
					else
					{
						if (R.isGermany())
						{
							this.listPickerLanguage.SelectedIndex = 3;
						}
						else
						{
							if (R.isEnglish())
							{
								this.listPickerLanguage.SelectedIndex = 2;
							}
						}
					}
				}
			}
			this.initState = true;
		}
		protected override void OnPageIn(object[] object_0)
		{
			this.initData();
		}
		private void languageSelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (!this.initState)
			{
				return;
			}
			this.showProgressCover(strings.Set_LanguageChangeTip);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.doLanguageChange();
				List<UITask> list = new List<UITask>();
				list.Add(new UITask(new UITaskDlg(this.onEndChangeLanguage), 0u));
				UITaskManager uITaskManager = new UITaskManager(list, null);
				uITaskManager.StartTasks(1000u);
			});
		}
		public void onEndChangeLanguage()
		{
			this.hideProgressCover();
		}
		private void doLanguageChange()
		{
			string text = "";
			if (this.listPickerLanguage.SelectedIndex == 0)
			{
				text = "zh-CN";
			}
			else
			{
				if (this.listPickerLanguage.SelectedIndex == 1)
				{
					text = "zh-TW";
				}
				else
				{
					if (this.listPickerLanguage.SelectedIndex == 2)
					{
						text = "en-US";
					}
					else
					{
						if (this.listPickerLanguage.SelectedIndex == 3)
						{
							text = "de-DE";
						}
					}
				}
			}
			this.mSysSettings.strUserSetLanguage = text;
			GConfigMgr.saveSetting();
			CultureInfo culture = new CultureInfo(text);
			strings.Culture = culture;
			R.language_switch();
			this.toggleNewMsgNotify.refreshShow();
			this.toggleSound.refreshShow();
			this.toggleVibrate.refreshShow();
			this.toggleNotifyWithDetail.refreshShow();
			this.togglePlayBySpeakPhone.refreshShow();
			this.toggleAutoAddFriend.refreshShow();
			this.toggleExitComfirm.refreshShow();
			this.toggleBackground.refreshShow();
			this.toggleAutoSavePhotos.refreshShow();
			this.toggleNewMsgNotify.Text = strings.Set_Common_ToggleNewMsgNotify;
			this.toggleSound.Text = strings.Set_Common_ToggleSound;
			this.toggleVibrate.Text = strings.Set_Common_ToggleVibrate;
			this.toggleNotifyWithDetail.Text = strings.Set_Common_ToggleNotifyWithDetail;
			this.togglePlayBySpeakPhone.Text = strings.Set_Common_TogglePlayBySpeakPhone;
			this.toggleAutoAddFriend.Text = strings.Set_Common_ToggleAutoAddFriend;
			this.toggleExitComfirm.Text = strings.Set_Common_ToggleExitComfirm;
			this.toggleAutoSavePhotos.Text = strings.Set_Common_IsSavePhotos;
			this.toggleBackground.Text = strings.Background_Task;
			EventCenter.postEvent(EventConst.ON_UI_LANGUAGE_CHANGED, null, null);
			ServiceCenter.sceneNewSync.doScene(1, syncScene.MM_NEWSYNC_SCENE_OTHER);
			SessionPackMgr.setSessionKey(null);
		}
		private void skinSelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (!this.initState)
			{
				return;
			}
			MMThemeTypes mMThemeTypes;
			if (this.listPickerSkin.SelectedIndex == 0)
			{
				mMThemeTypes = MMThemeTypes.COOL_BLACK_THEME;
			}
			else
			{
				mMThemeTypes = MMThemeTypes.NORMAL_THEME;
			}
			MMThemeTypes themeType = MMTheme.getThemeType();
			if (mMThemeTypes != themeType)
			{
				MMTheme.GetInstance().ChangeTheme(mMThemeTypes);
				MMTheme.SaveThemeType(mMThemeTypes);
			}
			this.toggleNewMsgNotify.refreshShow();
			this.toggleSound.refreshShow();
			this.toggleVibrate.refreshShow();
			this.toggleNotifyWithDetail.refreshShow();
			this.togglePlayBySpeakPhone.refreshShow();
			this.toggleAutoAddFriend.refreshShow();
			this.toggleExitComfirm.refreshShow();
			this.toggleAutoSavePhotos.refreshShow();
			this.toggleBackground.refreshShow();
		}
		public void DoFinish(object sender, RoutedEventArgs e)
		{
			if (this.mFlagSettingsChanged)
			{
				GConfigMgr.saveSetting();
				this.mFlagSettingsChanged = false;
			}
			if (this.mFlagAccountStatusChanged)
			{
				ServiceCenter.sceneNewSync.doScene(1, syncScene.MM_NEWSYNC_SCENE_OTHER);
				this.mFlagAccountStatusChanged = false;
			}
		}
		public void listPickerLanguage_Click(object sender, RoutedEventArgs e)
		{
			if (this.listPickerLanguage.ListPickerMode == ListPickerMode.Normal)
			{
				double verticalOffset = this.scrollViewer.get_VerticalOffset();
				if (verticalOffset < 400.0)
				{
					this.scrollViewer.ScrollToVerticalOffset(400.0);
				}
			}
		}
		private void initData()
		{
			this.mFlagSettingsChanged = false;
			this.mFlagAccountStatusChanged = false;
			OnToggleStateChanged onToggleStateChanged = new OnToggleStateChanged(this.checkedStateChanged);
			this.toggleNewMsgNotify.onToggleStateChanged = onToggleStateChanged;
			this.toggleSound.onToggleStateChanged = onToggleStateChanged;
			this.toggleVibrate.onToggleStateChanged = onToggleStateChanged;
			this.toggleNotifyWithDetail.onToggleStateChanged = onToggleStateChanged;
			this.togglePlayBySpeakPhone.onToggleStateChanged = onToggleStateChanged;
			this.toggleAutoAddFriend.onToggleStateChanged = onToggleStateChanged;
			this.toggleExitComfirm.onToggleStateChanged = onToggleStateChanged;
			this.toggleBackground.onToggleStateChanged = onToggleStateChanged;
			this.toggleAutoSavePhotos.onToggleStateChanged = onToggleStateChanged;
			this.toggleNewMsgNotify.Text = strings.Set_Common_ToggleNewMsgNotify;
			this.toggleSound.Text = strings.Set_Common_ToggleSound;
			this.toggleVibrate.Text = strings.Set_Common_ToggleVibrate;
			this.toggleNotifyWithDetail.Text = strings.Set_Common_ToggleNotifyWithDetail;
			this.togglePlayBySpeakPhone.Text = strings.Set_Common_TogglePlayBySpeakPhone;
			this.toggleAutoAddFriend.Text = strings.Set_Common_ToggleAutoAddFriend;
			this.toggleExitComfirm.Text = strings.Set_Common_ToggleExitComfirm;
			this.toggleAutoSavePhotos.Text = strings.Set_Common_IsSavePhotos;
			this.toggleBackground.Text = strings.Background_Task;
			this.mSysSettings = GConfigMgr.settings;
			if (this.mSysSettings != null)
			{
				this.mSysSettings.bIsNewMsgNotifyOn = ServiceCenter.pushNotifyMgr.getEnable();
				this.toggleNewMsgNotify.IsChecked = this.mSysSettings.bIsNewMsgNotifyOn;
				this.toggleSound.IsChecked = this.mSysSettings.bIsSoundOn;
				this.toggleVibrate.IsChecked = this.mSysSettings.bIsVibrateOn;
				this.toggleNotifyWithDetail.IsChecked = !AccountMgr.DisablePushMsgDetail;
				this.togglePlayBySpeakPhone.IsChecked = !this.mSysSettings.bIsPlayBySpeakPhone;
			}
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount != null)
			{
				this.toggleAutoAddFriend.IsChecked = !AccountMgr.DisableAutoAddFriendWhenReply;
			}
			this.toggleExitComfirm.IsChecked = ConfigMgr.getBool("Set_Common_ToggleExitComfirm", true);
			this.toggleAutoSavePhotos.IsChecked = ConfigMgr.getBool("Set_Common_AutoSavePhotos", true);
			this.toggleBackground.IsChecked = GConfigMgr.getBool("BackgroundServiceOn", true);
			this.initSelector();
		}
		public ApplicationBar GetApplicationBar()
		{
			return null;
		}
		private void checkedStateChanged(object sender, bool isCheckOn)
		{
			if (this.initState)
			{
				if (sender == this.toggleNewMsgNotify)
				{
					this.mSysSettings.bIsNewMsgNotifyOn = isCheckOn;
					ServiceCenter.pushNotifyMgr.setEnable(this.mSysSettings.bIsNewMsgNotifyOn);
					GConfigMgr.saveSetting();
				}
				if (sender == this.toggleSound)
				{
					this.mSysSettings.bIsSoundOn = isCheckOn;
					GConfigMgr.saveSetting();
				}
				if (sender == this.toggleVibrate)
				{
					this.mSysSettings.bIsVibrateOn = isCheckOn;
					GConfigMgr.saveSetting();
				}
				if (sender == this.toggleNotifyWithDetail)
				{
					AccountMgr.DisablePushMsgDetail = !isCheckOn;
					this.mFlagAccountStatusChanged = true;
				}
				if (sender == this.togglePlayBySpeakPhone)
				{
					this.mSysSettings.bIsPlayBySpeakPhone = !isCheckOn;
					GConfigMgr.saveSetting();
				}
				if (sender == this.toggleAutoAddFriend)
				{
					AccountMgr.DisableAutoAddFriendWhenReply = !isCheckOn;
					this.mFlagAccountStatusChanged = true;
				}
				if (sender == this.toggleBackground)
				{
					GConfigMgr.setBool("BackgroundServiceOn", isCheckOn);
				}
				if (sender == this.toggleExitComfirm)
				{
					ConfigMgr.setBool("Set_Common_ToggleExitComfirm", isCheckOn);
				}
				if (sender == this.toggleAutoSavePhotos)
				{
					ConfigMgr.setBool("Set_Common_AutoSavePhotos", isCheckOn);
				}
			}
		}
		private void checkedOn(object sender, EventArgs e)
		{
			this.checkedStateChanged(sender, true);
		}
		private void checkedOff(object sender, EventArgs e)
		{
			this.checkedStateChanged(sender, false);
		}
		private bool hasFlag(uint status, int type)
		{
			return ((ulong)status & (ulong)((long)type)) != 0uL;
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, (SolidColorBrush)Application.get_Current().get_Resources().get_Item("HalfOpacityBrush1"), false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Setting/CommonSettingView.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.scrollViewer = (ScrollViewer)base.FindName("scrollViewer");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.toggleNewMsgNotify = (MMToggleSwitch)base.FindName("toggleNewMsgNotify");
			this.toggleNotifyWithDetail = (MMToggleSwitch)base.FindName("toggleNotifyWithDetail");
			this.toggleSound = (MMToggleSwitch)base.FindName("toggleSound");
			this.toggleVibrate = (MMToggleSwitch)base.FindName("toggleVibrate");
			this.togglePlayBySpeakPhone = (MMToggleSwitch)base.FindName("togglePlayBySpeakPhone");
			this.toggleAutoAddFriend = (MMToggleSwitch)base.FindName("toggleAutoAddFriend");
			this.toggleAutoSavePhotos = (MMToggleSwitch)base.FindName("toggleAutoSavePhotos");
			this.toggleBackground = (MMToggleSwitch)base.FindName("toggleBackground");
			this.toggleExitComfirm = (MMToggleSwitch)base.FindName("toggleExitComfirm");
			this.listPickerLanguage = (ListPicker)base.FindName("listPickerLanguage");
			this.listPickerSkin = (ListPicker)base.FindName("listPickerSkin");
		}
	}
}
